package cn.e4j.modular.crm.controller;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.core.util.DateUtils;
import cn.e4j.core.util.LangUtils;
import cn.e4j.core.util.StringUtils;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.crm.entity.GwakT;
import cn.e4j.modular.crm.entity.GwaklT;
import cn.e4j.modular.crm.entity.GwalT;
import cn.e4j.modular.crm.service.GwakTService;
import cn.e4j.modular.crm.service.GwalTService;
import cn.e4j.modular.erp.controller.ErpLogic;
import cn.e4j.modular.utils.CrmExceptionEnum;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 客户资料维护
 * Created by miaoyl on 2019-1-11.
 */
@Controller
@RequestMapping("/crm/gwai300")
public class Gwai300Controller extends BaseController {

    @Autowired
    private GwakTService gwakTService;

    @Autowired
    private GwalTService gwalTService;

    @Autowired
    private ErpLogic erpLogic;

    /**
     * 跳转客户等级分类管理页面
     */
    @RequiresPermissions("crm:gwai300:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/gwai300.html";
    }

    /**
     * 跳转到查看编辑的页面
     */
    @RequestMapping("/gwai300_add")
    public String addView() {
        return "/pc/crm/gwai300_edit.html";
    }

    /**
     * 查询客户资料列表
     */
    @RequestMapping("/getHeadlist")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData getHeadlist(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getHeadList(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询币种
     */
    @RequestMapping("/getGwacList")
    @ResponseBody
    public ResponseData getGwacList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwacList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询客户分类数据
     */
    @RequestMapping("/getGwafList")
    @ResponseBody
    public ResponseData getGwafList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwafList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询客户渠道数据
     */
    @RequestMapping("/getGwaeList")
    @ResponseBody
    public ResponseData getGwaeList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwaeList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询客户等级数据
     */
    @RequestMapping("/getGwaqList")
    @ResponseBody
    public ResponseData getGwaqList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwaqList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询生命周期数据
     */
    @RequestMapping("/getGwarList")
    @ResponseBody
    public ResponseData getGwarList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwarList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询行业分类数据
     */
    @RequestMapping("/getGwagList")
    @ResponseBody
    public ResponseData getGwagList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwagList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询税种数据
     */
    @RequestMapping("/getGweaList")
    @ResponseBody
    public ResponseData getGweaList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGweaList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询归属法人数据
     */
    @RequestMapping("/getSysOrgList")
    @ResponseBody
    public ResponseData getSysOrgList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getSysOrgList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 查询仓库资料数据
     */
    @RequestMapping("/getGwasList")
    @ResponseBody
    public ResponseData getGwasList(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("GWASENT", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwakTService.getGwasList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 新增
     */
    @RequestMapping("/add")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData add(GwakT gwakT, GwaklT gwaklT, @DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        gwaklT.setGWAKL003(inDto.getString("GWAKL003"));
        gwaklT.setGWAKL004(inDto.getString("GWAKL004"));
        // 判断编号是否重复
        GwakT theGwakT = gwakTService.getByGwak001(shiroUser.getDBC(), gwakT.getGWAK001());
        if (theGwakT != null) {
            //throw new ServiceException(CrmExceptionEnum.EXISTED_THE_CODE);
            return new ErrorResponseData(CrmExceptionEnum.EXISTED_THE_CODE.getCode(),
                    CrmExceptionEnum.EXISTED_THE_CODE.getMessage());
        }
        gwakTService.add(gwakT, gwaklT, inDto);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping("/edit")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData edit(GwakT gwakT, GwaklT gwaklT, @DtoParam DtoWapper dtoWapper) {
        gwakTService.edit(gwakT, gwaklT);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping("/del")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData del(GwakT gwakT, GwaklT gwaklT) {
        gwakTService.delete(gwakT, gwaklT);
        return SUCCESS_TIP;
    }

    /**
     * 批量删除数据
     */
    @RequestMapping("/delDataBatch")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData deleteDataBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwakT> gwakTList = inDto.getReqList(GwakT.class);
        gwakTService.delDataBatch(gwakTList);
        return SUCCESS_TIP;
    }

    /**
     * 查询ERP数据库列表
     */
    @RequestMapping("/getERPList")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData getERPList(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Map<String, Object>> result = gwakTService.getERPList(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询客户资料列表
     */
    @RequestMapping("/getDetailList")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData getDetailList(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ent", shiroUser.getDBC());
        inDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
        List<Map<String, Object>> result = gwalTService.getDetailList(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询最大序号值
     */
    @RequestMapping("/getMaxGwal002")
    @ResponseBody
    public ResponseData getMaxGwal002(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        String result = gwalTService.getMaxGwal002(shiroUser.getDBC(), inDto.getString("GWAL001"));
        return ResponseData.success(result);
    }

    /**
     * 查询区域资料
     */
    @RequestMapping("/getGwadList")
    @ResponseBody
    public ResponseData getGwadList(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Map<String, Object>> result = gwalTService.getGwadList(inDto);
        return ResponseData.success(result);
    }

    /**
     * 新增客户联系人
     */
    @RequestMapping("/addDetail")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData addDetail(GwalT gwalT, @DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        gwalT.setGWAL018(inDto.getString("GWAL018"));
        // 判断是否常用地址
        GwalT theGwalT = gwalTService.getByGwal003(shiroUser.getDBC(), gwalT.getGWAL001());
        if (theGwalT != null && gwalT.getGWAL003().equals("Y")) {
            //throw new ServiceException(CrmExceptionEnum.EXISTED_THE_CODE);
            return new ErrorResponseData(CrmExceptionEnum.EXISTED_THE_GWAL.getCode(),
                    CrmExceptionEnum.EXISTED_THE_GWAL.getMessage());
        }
        gwalTService.add(gwalT);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping("/editDetail")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData editDetail(GwalT gwalT, @DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        gwalT.setGWAL018(inDto.getString("GWAL018"));
        // 判断是否常用地址
        GwalT theGwalT = gwalTService.getByGwal003(shiroUser.getDBC(), gwalT.getGWAL001());
        if (theGwalT != null && (!gwalT.getGWAL002().equals(theGwalT.getGWAL002())) && gwalT.getGWAL003().equals("Y")) {
            return new ErrorResponseData(CrmExceptionEnum.EXISTED_THE_GWAL.getCode(),
                    CrmExceptionEnum.EXISTED_THE_GWAL.getMessage());
        }
        gwalTService.edit(gwalT);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping("/delDetail")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData delDetail(GwalT gwalT) {
        gwalTService.delete(gwalT);
        return SUCCESS_TIP;
    }

    /**
     * 批量删除数据
     */
    @RequestMapping("/delDetailDataBatch")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData delDetailDataBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwalT> gwalTList = inDto.getReqList(GwalT.class);
        gwalTService.delDataBatch(gwalTList);
        return SUCCESS_TIP;
    }

    /**
     * 新增客户联系人
     */
    @RequestMapping("/insertERP")
    @ResponseBody
    public ResponseData insertERP(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        JSONArray json = new JSONArray();
        try {
            json = erpLogic.getERPService("insertErpGwak",inDto);
        }catch (NoSuchMethodException e) {
            e.printStackTrace();
        }catch(Exception e){
            e.printStackTrace();
        }
        /*String[] gwak001s = inDto.getString("gwak001_list").split(",");
        String[] MB001s = inDto.getString("mb001_list").split(",");
        ShiroUser shiroUser = ShiroKit.getUser();
        JSONArray json = new JSONArray();
        for (String gwak001 : gwak001s) {
            //一条客户资料数据
            Dto gwakDto = Dtos.newDto();
            gwakDto.put("ent", shiroUser.getDBC());
            gwakDto.put("lang", LangUtils.getLang(shiroUser.getLANG()));
            gwakDto.put("gwak001", gwak001);
            Dto info = gwakTService.getGwakData(gwakDto);
            for (String MB001 : MB001s) {
                //是否写入成功
                String result = "N";
                //目标数据库信息
//                Dto dbinfo = this.gwakTService.getDBinfo(MB001);
                Dto outDto = Dtos.newDto();
                if (MB001 != null) {
                    outDto.put("MB001", MB001);//获取目标数据库
                    outDto.put("MA001", info.getString("GWAK001"));
                    outDto.put("MA002", info.getString("GWAKL003"));
                    outDto.put("MA003", info.getString("GWAKL004"));
                    outDto.put("MA004", info.getString("GWAK050"));
                    outDto.put("MA005", info.getString("GWAK031"));//联系人
                    outDto.put("MA006", info.getString("GWAK030"));//电话1
//                    outDto.put("MA007", info.getString("GWAK050"));//电话2
//                    outDto.put("MA010", info.getString("GWAK007"));
                    if (info.getString("GWAK051").equals("NULL")) {
                        outDto.put("MA011", "");
                    } else {
                        outDto.put("MA011", info.getBigDecimal("gwak051"));
                    }
                    if (info.getString("GWAK052").equals("NULL")) {
                        outDto.put("MA012", "");
                    } else {
                        outDto.put("MA012", info.getBigDecimal("GWAK052"));
                    }
                    outDto.put("MA014", info.getString("GWAK008"));
                    outDto.put("MA017", info.getString("GWAK023"));
                    outDto.put("MA018", info.getString("GWAK024"));
                    outDto.put("MA019", info.getString("GAWK021"));
                    outDto.put("MA023", info.getString("GAWK028"));//注册地址
                    if (!(info.getString("GWAL018_fp").isEmpty())) {
                        outDto.put("MA025", info.getString("GWAL018_fp"));//gwal018 where gwal003='I' 发票地址
                    }
                    if (!(info.getString("GWAL018_sh").isEmpty())) {
                        outDto.put("MA027", info.getString("gwal018_sh"));//gwal018 where gwal003='D' 送货地址
                    }
                    outDto.put("MA031", info.getString("GWAK060_NAME"));
                    outDto.put("MA032", "N");
                    outDto.put("MA033", 0);
                    outDto.put("MA034", 0);
                    outDto.put("MA035", "2");
                    outDto.put("MA036", 0);
                    outDto.put("MA037", "A");
//                    outDto.put("MA038", info.getString("GWAK012"));//税种
                    outDto.put("MA038", "1");//税种
                    outDto.put("MA039", "1");
                    outDto.put("MA041", "2");
                    outDto.put("MA042", "1");
                    outDto.put("MA044", 0);
                    outDto.put("MA045", 0);
                    outDto.put("MA047", "112201"); //账款科目
//                    outDto.put("MA048", "1");
                    outDto.put("MA059", 0);
                    outDto.put("MA060", 0);
                    outDto.put("MA061", 0);
                    outDto.put("MA066", "N");
                    outDto.put("MA067", 0);
                    outDto.put("MA074", "1121");
                    outDto.put("MA075", "86");
                    outDto.put("MA082", "N");
                    outDto.put("MA083", info.getString("GWAK060"));//付款条件
                    outDto.put("MA084", "N");
                    outDto.put("MA086", "N");
                    outDto.put("MA087", "2");
                    outDto.put("MA088", "1");
                    outDto.put("MA089", "1");
                    outDto.put("MA090", 1);
                    outDto.put("MA091", 1);
                    outDto.put("MA092", 1);
                    outDto.put("MA093", 1);
                    outDto.put("MA094", 1);
                    outDto.put("MA095", 0);
                    outDto.put("MA096", "1");
                    outDto.put("MA097", "1");
                    //抓税率
                    if (info.getString("GWEA006") == null || info.getString("GWAK004").isEmpty()) {
                        outDto.put("MA101", 0.16);
                    } else {
                        outDto.put("MA101", info.getBigDecimal("GWEA006"));
                    }
                    outDto.put("MA103", "1");
                    outDto.put("MA104", 0);
                    outDto.put("MA105", "220301");
                    outDto.put("MA106", "N");
                    outDto.put("MA109", 0);
                    outDto.put("MA110", 0);
                    outDto.put("MA111", 0);
                    outDto.put("MA113", "N");
//                    outDto.put("UDF01", info.getString("GWAK004"));
                    outDto.put("COMPANY", MB001);
//                    outDto.put("CREATOR", shiroUser.getBIZ_CODE());
//                    outDto.put("USR_GROUP", "");
//                    outDto.put("CREATE_DATE", DateUtils.getDate("yyyyMMdd"));
                    outDto.put("FLAG", 1);

                    //判断客户编号在ERP中是否存在 不存在就新增一笔数据
                    Dto inDto2 = Dtos.newDto();
                    Dto outDto2 = Dtos.newDto();
                    inDto2.put("GWAK001", info.getString("GWAK001"));
                    inDto2.put("MB001", MB001);
                    outDto2 = this.gwakTService.selectByGwak001(inDto2);
                    int count = 0;
                    if (outDto2 == null) {
                        //将客户资料插入指定ERP数据库
                        try {
                            count = this.gwakTService.insertERP(outDto);
                        } catch (Exception e) {
                            JSONObject jo = new JSONObject();
                            jo.put("SYNCRESULT", result);//同步结果  Y  N syncresult
                            jo.put("GWAK001", info.getString("GWAK001"));//客户编号
                            jo.put("GWAKL003", info.getString("GWAKL003"));//客户名称
                            jo.put("REMARK", e.getMessage());
                            if (MB001 != null) {
                                jo.put("MB002", MB001);//erp公司
                            } else {
                                jo.put("MB002", "");//erp公司
                            }
                            json.add(jo);
                        }

                    } else {

                        try {
                            count = this.gwakTService.updateERP(outDto);
                        } catch (Exception e) {
                            JSONObject jo = new JSONObject();
                            jo.put("SYNCRESULT", result);//同步结果  Y  N syncresult
                            jo.put("GWAK001", info.getString("GWAK001"));//客户编号
                            jo.put("GWAKL003", info.getString("GWAKL003"));//客户名称
                            jo.put("REMARK", e.getMessage());
                            if (MB001 != null) {
                                jo.put("MB002", MB001);//erp公司
                            } else {
                                jo.put("MB002", "");//erp公司
                            }
                            json.add(jo);
                        }
                    }
                    if (count > 0) {
                        result = "Y";
                    }

                }
                JSONObject jo = new JSONObject();
                jo.put("SYNCRESULT", result);//同步结果  Y  N syncresult
                jo.put("GWAK001", info.getString("GWAK001"));//客户编号
                jo.put("GWAKL003", info.getString("GWAKL003"));//客户名称
                jo.put("REMARK", "");
                if (MB001 != null) {
                    jo.put("MB002", MB001);//erp公司
                } else {
                    jo.put("MB002", "");//erp公司
                }
                json.add(jo);
            }
        }*/
        return ResponseData.success(json);
    }

    /**
     * 获取新增默认值
     */
    @RequestMapping("/getAddData")
    @ResponseBody
    public ResponseData getAddData(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        Dto addDataDto = gwakTService.getAddData(inDto);
        return new SuccessResponseData(addDataDto);
    }

    /**
     * 查询是否重复
     */
    @RequestMapping("/getCount")
    @ResponseBody
    public ResponseData getCount(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Dto outDto = gwakTService.getCount(inDto, inDto.getString("GWAKL004"));
        return ResponseData.success(outDto);
    }

    /**
     * 修改客户状态
     */
    @RequestMapping("/updateStatus")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData updateStatus(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwakT> gwakTList = inDto.getReqList(GwakT.class);
        List<GwaklT> gwaklTList = inDto.getReqList(GwaklT.class);
        String gwak001 = "";
        String gwak001_S = "";
        for (GwakT gwakT : gwakTList) {
            if("T".equals(gwakT.getGWAKACTI())){
                inDto.put("GWAK001", gwakT.getGWAK001());
                GwakT queryGwak = this.gwakTService.getGwak(inDto);
                if(ToolUtil.isEmpty(queryGwak.getGWAK057()) || ToolUtil.isEmpty(queryGwak.getGWAK076()) || ToolUtil.isEmpty(queryGwak.getGWAK050()) || ToolUtil.isEmpty(queryGwak.getGWAK053()) ||
                        ToolUtil.isEmpty(queryGwak.getGWAK031()) || ToolUtil.isEmpty(queryGwak.getGWAK030()) || ToolUtil.isEmpty(queryGwak.getGWAK068()) || ToolUtil.isEmpty(queryGwak.getGWAK069()) ||
                        ToolUtil.isEmpty(queryGwak.getGWAK051()) || ToolUtil.isEmpty(queryGwak.getGWAK074()) || ToolUtil.isEmpty(queryGwak.getGWAK011()) || ToolUtil.isEmpty(queryGwak.getGWAK078()) ||
                        ToolUtil.isEmpty(queryGwak.getGWAK079()) || ToolUtil.isEmpty(queryGwak.getGWAK080()) || ToolUtil.isEmpty(queryGwak.getGWAK081()) || ToolUtil.isEmpty(queryGwak.getGWAK075())){
                    gwak001 = gwak001 + gwakT.getGWAK001()+",";
                    //return ResponseData.error(500, "存在必输字段未维护的资料！");
                }
                if("Y".equals(queryGwak.getGWAK086())){ //变更后变更文件必输
                    if(queryGwak.getGWAK087() == null){
                        gwak001_S = gwak001_S + gwakT.getGWAK001()+",";
                    }
                }
            }
        }
        if(! "".equals(gwak001)){
            gwak001 = StringUtils.substringBeforeLast(gwak001, ",");
            return ResponseData.error(500,"客户编号"+gwak001+"资料不完整！");
        }
        if(! "".equals(gwak001_S)){
            gwak001_S = StringUtils.substringBeforeLast(gwak001_S, ",");
            return ResponseData.error(500,"客户编号"+gwak001_S+"变更文件未上传！");
        }
        gwakTService.updateStatus(gwakTList);
        return SUCCESS_TIP;
    }

    /**
     * 修改客户状态及退回信息
     */
    @RequestMapping("/updateBackInfo")
    @RequiresPermissions("crm:gwai300:init")
    @ResponseBody
    public ResponseData updateBackInfo(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        JSONObject jsonObject = inDto.getReqJsonObject();
        List<GwakT> gwakTList = JSONObject.parseArray(jsonObject.getString("_xdata"), GwakT.class);
        String GWAK088 = jsonObject.getString("GWAK088");
        gwakTService.updateBackInfo(gwakTList, GWAK088);
        return SUCCESS_TIP;
    }

    /**
     * 获取新增默认值
     */
    @RequestMapping("/getAddDetailData")
    @ResponseBody
    public ResponseData getAddDetailData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Dto outDto = Dtos.newDto();
        ShiroUser shiroUser = ShiroKit.getUser();
        outDto.put("GWALORIG", shiroUser.getORG_ID());
        outDto.put("GWAKORIG", shiroUser.getORG_ID());
        outDto.put("GWALORIU", shiroUser.getID());
        outDto.put("GWALORIU_NAME", shiroUser.getNAME());
        outDto.put("GWALDATE", DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
        outDto.put("GWALORIG_NAME", shiroUser.getSysOrgT().getNAME());
        outDto.put("MOBILE", shiroUser.getMOBILE());
        return new SuccessResponseData(outDto);
    }
}
